﻿using System.Linq;

namespace System.Management.HyperV.Model
{
    /// <summary>
    /// Represents a physical computer system.
    /// </summary>
    public sealed class Host : Msvm.ComputerSystem
    {
        #region Constructor
        internal Host(ManagementObject wmiInstance)
            : base(wmiInstance)
        {
        }
        #endregion

        public Guest[] Guests
        {
            get
            {
                var query = new ObjectQuery("SELECT * FROM Msvm_ComputerSystem WHERE Description = 'Microsoft Virtual Machine' ");

                using (var searcher = new ManagementObjectSearcher(this.WmiInstance.Scope, query))
                {
                    var searchResults = from mo in searcher.Get().OfType<ManagementObject>()
                                        select new Model.Guest(mo);

                    return searchResults.ToArray();
                }
            }
        }
    }
}
